package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_fItemsDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;
	
	
	public ASM_fItemsDS(Context context) {
		this.context = context;
		dbHelper  = new ASM_DB(context);
		
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_fItems det) 
	{
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		
		ContentValues values = new ContentValues();
		
		values.put(ASM_DB.asmFItems_SKUCode, det.getAsmFItems_SKUCode());
		values.put(ASM_DB.asmFItems_ItemCode, det.getAsmFItems_ItemCode());
		values.put(ASM_DB.asmFItems_ItemName,det.getAsmFItems_ItemName());
		values.put(ASM_DB.asmFItems_BrandCode,det.getAsmFItems_BrandCode());
		values.put(ASM_DB.asmFItems_NOUCase,det.getAsmFItems_NOUCase());
	


		
		count = (int) dB.insert(ASM_DB.ASM_FITEMS, null, values);

		dB.close();
		return count;
		
	}
	public ArrayList<String> getselectItems(String Brandcode) 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		ArrayList<String> Details = new ArrayList<String>();
	
		String selectQuery = "select ItemCode,ItemName from fItems where BrandCode = '"+Brandcode+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
			String Itemname = cursor.getString(1)+" -:- "+cursor.getString(0);
			Details.add(Itemname);
			
			
			
		}
		
		return Details;
	}
	public ArrayList<ASM_fItems> getFitems(String Brandcode) 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		ArrayList<ASM_fItems> Itemname = new ArrayList<ASM_fItems>();

		String selectQuery = "select ItemName,ItemCode from fItems where BrandCode = '"+Brandcode+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
			ASM_fItems itemLoc=new ASM_fItems();
			
			itemLoc.setAsmFItems_ItemName(cursor.getString(0));
			itemLoc.setAsmFItems_ItemCode(cursor.getString(1));

			Itemname.add(itemLoc);
			
			
			
		}
		
		return Itemname;
	}
}
